<template>
	<view class="container">
		<view class="flex   justify-center">
			<view class="UCenter-bg margin-top-xxxl" style='background-image:url("https://www.hozenn.com/iot/logo/logo_xmh.png")'>
			</view>
		</view>
		<view class='form-box'>

			<form class="">

				<view class=" padding-xs flex align-center">
					<view class="flex-sub ">
						<view class=" text-xl padding text-center">
							<text class="text-grey text-xl text-bold ">智能精准饲喂</text>
						</view>
						<!-- <view class="padding text-gray">页面大标题，用于结果页等单一信息页</view> -->
					</view>
				</view>

				<!-- <view class="cu-form-group margin-top round">
					<text class="cuIcon-people text-grey "></text>
					<input class="cus-input" placeholder-class="phcolor" placeholder="账号/手机号码" value=""
						name="userid" bindinput="getUserid"></input>
				</view>

				<view class="padding-xs"></view>
				<view class="cu-form-group margin-top round">
					<text class="cuIcon-keyboard text-grey"></text>
					<input class="cus-input" type="password" placeholder-class="phcolor" placeholder="密码"
						value="" name="pwd" bindinput="getPwd"></input>
				</view>

				<button bindtap="onLogin" class="round cu-btn block login-btn margin-tb-lg margin-lr-xs lg"><text>
						登录</text> </button> -->

			</form>
		</view>
	</view>
</template>

<script>
	import * as api from 'common/api.js';
	export default {
		data() {
			return {

			}
		},
		onShow: function() {
			console.info("show boot")
			var that = this
			setTimeout(function(){that.init()},200)
			
		},
		onLoad() {

		},
		methods: {
			init() {
				this.checkVersion()
			},
			checkLogin() {
				console.info("检查用户")
				var token
				try {
					token = uni.getStorageSync('token');
					if (token) {
						console.log(token);
					} else {
						console.info("无用户信息")
						console.info(res.msg);
						uni.redirectTo({
							url: '/pages/login/login'
						});
						return
					}
				} catch (e) {
					// error
				}

				api.myRequest({
					url: '/Api/User/Info',
					method: 'GET',
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'Authorization':'Bearer ' + token + ''
					},
					data: {},
				}).then(res => {

					if (res.code >= 0 && res.code!=401) {
						console.info("用户存在，跳转")
						try {
							uni.setStorageSync('userinfo', JSON.stringify(res.data));
						} catch (e) {
							console.error(e)
						}
						uni.switchTab({
							url: '/pages/tabbar/topo/topo'
						});



					} else {
						console.info("用户失效")
						console.info(res.msg);
						uni.redirectTo({
							url: '/pages/login/login'
						});
					}

				}).catch(err => {
					console.log(err)
				})
			},
			//检查版本更新情况
			checkVersion() {
				var that = this
				//模拟接口获取最新版本号，版本号固定为整数
				getApp().getRemoteVer().then(function(res) {
					console.info(res)
					if (res.code >= 0) {

						//#ifdef H5
						//浏览器调试模式下
						const appInfo = uni.getAppBaseInfo()
						console.info(appInfo)
						const selfVersionCode = Number(appInfo.appVersionCode) //当前App版本号
						const remoteVersionCode = Number(res.data.versionCode)
						const remoteVersionName = res.data.versionName
						console.info("selfVersionCode:", selfVersionCode, "remoteVersionCode:", remoteVersionCode)
						//线上版本号高于当前，进行在线升级
						if (selfVersionCode < remoteVersionCode) {
							console.info("find update!")
							let platform = uni.getSystemInfoSync().platform //手机平台
							console.info("platform", platform)
							//安卓手机弹窗升级
							if (platform === 'android') {
								setTimeout(() => {
									uni.navigateTo({
										url: '/pages/upgrade/upgrade'
									})
								}, 500);
						
							} //IOS无法在线升级提示到商店下载
							else {
								uni.showModal({
									title: '发现新版本:' + remoteVersionName,
									content: '请到AppStore进行升级',
									showCancel: false
								})
								that.checkLogin()
							}
						} else {
							//无更新
							that.checkLogin()
						}
						// #endif
						

						// #ifdef APP-PLUS
						//真机模式下
						plus.runtime.getProperty(plus.runtime.appid, function(appInfo) {
							console.log("云打包，安心打包方式获取设备信息:");
							console.info(appInfo)
							const selfVersionCode = Number(appInfo.versionCode) //当前App版本号
							const remoteVersionCode = Number(res.data.versionCode)
							const remoteVersionName = res.data.versionName
							console.info("selfVersionCode:", selfVersionCode,
								"remoteVersionCode:", remoteVersionCode)
							//线上版本号高于当前，进行在线升级
							if (selfVersionCode < remoteVersionCode) {
								console.info("find update!")
								let platform = uni.getSystemInfoSync().platform //手机平台
								//安卓手机弹窗升级
								if (platform === 'android') {
									setTimeout(() => {
										uni.navigateTo({
											url: '/pages/upgrade/upgrade'
										})
									}, 500);
						
								} //IOS无法在线升级提示到商店下载
								else {
									uni.showModal({
										title: '发现新版本:' + remoteVersionName,
										content: '请到AppStore进行升级',
										showCancel: false
									})
								}
							} else {
								//无更新
								that.checkLogin()
							}
						});
						// #endif
						



					} else {
						//无更新
						that.checkLogin()
					}
				})
			}


		}
	}
</script>

<style>
	.page {
		background-color: #e78c1e;
		height: 100vh;
	}

	.container {
		position: absolute;
		top: 0;
		right: 0;
		bottom: 0;
		left: 0;
		/* background-image: url("https://www.hozenn.com/iot/img/bg1.png"); */
		background-color: #ffffff;
		background-size: 100% 100%;
		/* filter: blur(2rpx); */
		overflow: hidden;
		/* filter: blur(2rpx); */

	}

	.UCenter-bg {
		/* background-image: url("../../../images/profile.jpeg"); */
		background-size: cover;
		height: 200rpx;
		width: 460rpx;
		display: flex;
		justify-content: center;
		padding-top: 40rpx;
		overflow: hidden;
		position: relative;
		flex-direction: column;
		align-items: center;
		color: #fff;
		font-weight: 300;
		text-shadow: 0 0 3px rgba(0, 0, 0, 0.3);
	}
	
	.form-box {
		width: 83.3%;
		margin: 0 auto;
		margin-top: 10%;
		float: none;
		background-color: transparent;
	}
	
	.cu-form-group {
		/* background-color: var(--white); */
		background-color: rgba(150, 150, 150, 0.212);
		/* color: #fff; */
		padding: 1rpx 30rpx;
		display: flex;
		align-items: center;
		min-height: 90rpx;
		justify-content: space-between;
		margin: 10rpx;
		/* background-color: #000000aa; */
	}
	
	.cu-form-group+.cu-form-group {
		border-top: 1rpx solid #eee;
	}
	
	.phcolor {
		color: rgb(122, 126, 148) !important;
	}
	
	.cus-input {
		color: #cccccc !important;
	}
	
	.login-btn {
		background-color: rgba(80, 87, 185, 0.596) !important;
		color: #ffffff;
	}
	.cu-form-group>text[class*="cuIcon-"] {
		font-size: 36rpx;
		padding: 10rpx;
		box-sizing: border-box;
		padding-right: 20rpx;
	}
</style>